package edu.gatech.gui;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import edu.gatech.presenters.RegisterPresenter;
import edu.gatech.userclasses.SysAdmin;
import edu.gatech.userclasses.User;

public class RegisterPanel {
	private static JTextField txtPassword;
	private static JTextField txtUsername;
	private static User user = null;
	private static JRadioButton rdbtnPatient, rdbtnNurse, rdbtnDoctor, rdbtnAdmin;
	private SysAdmin currentAdmin;
	private JPanel panel;
	private RegisterPresenter presenter;
	public RegisterPanel(SysAdmin admin){
		currentAdmin = admin;
		JFrame register = new JFrame("Register Panel");
		register.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel registerPanel = new JPanel();
		
		register.setSize(640,480);
		
		register.getContentPane().add(registerPanel, BorderLayout.CENTER);
		registerPanel.setLayout(null);
		
		ButtonGroup group = new ButtonGroup();
				
		JButton btnRegister = new JButton("Register");
		btnRegister.setFont(new Font("Arial", Font.PLAIN, 10));
		btnRegister.setBounds(195, 236, 184, 21);
		registerPanel.add(btnRegister);
		
		txtPassword = new JTextField();
		txtPassword.setBounds(195, 179, 184, 21);
		registerPanel.add(txtPassword);
		txtPassword.setFont(new Font("Arial", Font.PLAIN, 10));
		txtPassword.setText("Password");
		txtPassword.setColumns(15);
		
		txtUsername = new JTextField();
		txtUsername.setBounds(195, 149, 184, 21);
		registerPanel.add(txtUsername);
		txtUsername.setFont(new Font("Arial", Font.PLAIN, 10));
		txtUsername.setText("Username");
		txtUsername.setColumns(15);
		
		rdbtnAdmin = new JRadioButton("Admin", false);
		rdbtnAdmin.setBounds(346, 208, 57, 21);
		registerPanel.add(rdbtnAdmin);
		rdbtnAdmin.setFont(new Font("Arial", Font.PLAIN, 10));
		group.add(rdbtnAdmin);
		
		rdbtnDoctor = new JRadioButton("Doctor", false);
		rdbtnDoctor.setBounds(287, 208, 57, 21);
		registerPanel.add(rdbtnDoctor);
		rdbtnDoctor.setFont(new Font("Arial", Font.PLAIN, 10));
		group.add(rdbtnDoctor);
		
		rdbtnNurse = new JRadioButton("Nurse", false);
		rdbtnNurse.setBounds(234, 208, 51, 21);
		registerPanel.add(rdbtnNurse);
		rdbtnNurse.setFont(new Font("Arial", Font.PLAIN, 10));
		group.add(rdbtnNurse);
		
		rdbtnPatient = new JRadioButton("Patient", true);
		rdbtnPatient.setBounds(173, 208, 59, 21);
		registerPanel.add(rdbtnPatient);
		rdbtnPatient.setFont(new Font("Arial", Font.PLAIN, 10));
		group.add(rdbtnPatient);
		
		panel = new JPanel();
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Register", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("Button.darkShadow")));
		panel.setBounds(162, 130, 253, 138);
		registerPanel.add(panel);
		btnRegister.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int radioButton = 0;
				if(rdbtnNurse.isSelected()){
					radioButton = 1;
				}
				else if(rdbtnDoctor.isSelected()){
					radioButton = 2;
				}
				else if(rdbtnAdmin.isSelected()){
					radioButton = 3;
				}
				presenter = new RegisterPresenter(currentAdmin);
				presenter.register(txtUsername.getText(), txtPassword.getText(), radioButton);
			}
		});
		
		MenuBar menuBar = new MenuBar(register);
        
        register.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        register.setTitle("Register Panel");
        register.setSize(600,480);
        register.setLocationRelativeTo(null); 
        register.setVisible(true);
	}
}
